package com.xiaochong.bitong.job.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ctc.wstx.util.DataUtil;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.bitong.job.config.hbase.HbaseBaseQueryComponent;
import com.xiaochong.service.common.config.redis.RedisServer;
import com.xiaochong.tir.common.data.hbasepo.*;
import com.xiaochong.tir.common.data.mapper.CurrencyGlobalInfoHbaseMapper;
import com.xiaochong.tir.common.data.po.CurrencyGlobalInfoHbase;
import com.xiaochong.tir.common.data.vo.*;
import com.xiaochong.tir.common.exception.ErrorDataException;
import com.xiaochong.tir.common.exception.hbase.HbaseCloseExcetion;
import com.xiaochong.tir.common.exception.hbase.HbaseConnectionExcetion;
import com.xiaochong.tir.common.exception.hbase.HbaseGetTableExcetion;
import com.xiaochong.tir.common.util.DateUtils;
import com.xiaochong.tir.common.util.HbaseTableUtils;
import com.xiaochong.tir.common.util.LogTraceKeysUtils;
import com.xiaochong.tir.common.util.RedisKeysUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;

/**
 * @Project : xc-tir
 * @Package Name : com.xiaochong.bitong.job.service
 * @Description : TODO
 * @Author : daizhiqing@xiaochong.com
 * @Creation Date : 2018年08月13日下午7:49
 * @ModificationHistory Who When What
 */
@Service
public class MarketIndecService {

    @Autowired
    CurrencyGlobalInfoHbaseMapper globalInfoHbaseMapper;
    @Autowired
    HbaseBaseQueryComponent hbaseBaseQueryComponent;

    @Autowired
    RedisServer redisServer;
    /**
     * 获取大盘数据
     * @param rowKey
     * @return
     * @throws HbaseConnectionExcetion
     * @throws HbaseGetTableExcetion
     * @throws IOException
     * @throws HbaseCloseExcetion
     */
    private String getBroaderData(String rowKey) throws HbaseConnectionExcetion, HbaseGetTableExcetion, IOException, HbaseCloseExcetion {
        String grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_NAME
                , HbaseTableUtils.HOME_INDEX_EVERY_DAY_RECORDING_TABLE_FAMILY
                , HbaseTableUtils.EVERY_DAY_BROADER_INDEX_QUALIFIER
                , rowKey );
        LogTrace.info("hbase大盘数据查询","是否存在数据"+rowKey, StringUtils.isBlank(grailStr)?"无数据":"有数据");
        return grailStr;
    }



    /**
     * 组装APP 3小时大盘曲线
     * @return
     * @throws HbaseCloseExcetion
     * @throws IOException
     * @throws HbaseGetTableExcetion
     * @throws HbaseConnectionExcetion
     */
    public ChartVo getBroaderIndexOfThreeHours() throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {

        int betweenHours = 3;
        ChartVo chartVo = new ChartVo();

        List<String> x = new LinkedList<>();
        List<String> y = new LinkedList<>();

        List<BroaderIndex> hlist = new ArrayList<>();
        int nowHours = LocalDateTime.now().getHour();
        Long hstart = System.currentTimeMillis();
        String rowKey ;
        if(nowHours < betweenHours){
            rowKey = DateUtils.getNextDayDateYMD(-1);
            String grailStr = getBroaderData(rowKey);
            if(StringUtils.isNotBlank(grailStr)){
                hlist.addAll(JSONObject.parseArray(grailStr, BroaderIndex.class)) ;
            }
        }
        rowKey = DateUtils.getCurrentDateString();
        String grailStr = getBroaderData(rowKey);
        if(StringUtils.isNotBlank(grailStr)){
            hlist.addAll(JSONObject.parseArray(grailStr, BroaderIndex.class));
        }
        LogTrace.info("大盘指数hbase数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));

        if (hlist.size() > 0) {
            for (BroaderIndex broaderIndex : hlist) {
                if(broaderIndex.getCreateTime()!= null && broaderIndex.getBroaderIndex()!= null){
                    //存入十二个小时以内数据
                    if (DateUtils.getDaysBetweenTwoHours(new Date(), broaderIndex.getCreateTime()) <= betweenHours) {
                        x.add(String.valueOf(broaderIndex.getCreateTime().getTime()));
                        y.add(broaderIndex.getBroaderIndex().setScale(2,BigDecimal.ROUND_DOWN).toString());
                    }
                }

            }
        }
        chartVo.setX(x);
        chartVo.setY(y);
        return  chartVo;
    }

    /**
     * 组装APP 24小时大盘曲线
     * @return
     * @throws HbaseCloseExcetion
     * @throws IOException
     * @throws HbaseGetTableExcetion
     * @throws HbaseConnectionExcetion
     */
    public ChartVo getBroaderIndexOf24Hours() throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {

        int betweenHours = 24;
        int betweenMin = 10;

        ChartVo chartVo = new ChartVo();

        List<String> x = new LinkedList<>();
        List<String> y = new LinkedList<>();

        List<BroaderIndex> hlist = new ArrayList<>();
        int nowHours = LocalDateTime.now().getHour();
        Long hstart = System.currentTimeMillis();
        String rowKey ;
        if(nowHours < betweenHours){
            rowKey = DateUtils.getNextDayDateYMD(-1);
            String grailStr = getBroaderData(rowKey);

            if(StringUtils.isNotBlank(grailStr)){
                hlist.addAll(JSONObject.parseArray(grailStr, BroaderIndex.class)) ;
            }
        }
        rowKey = DateUtils.getCurrentDateString();
        String grailStr = getBroaderData(rowKey);
        if(StringUtils.isNotBlank(grailStr)){
            hlist.addAll(JSONObject.parseArray(grailStr, BroaderIndex.class));
        }
        LogTrace.info("大盘指数hbase数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));

        if (hlist.size() > 0) {
            int temp = -1;
            for (BroaderIndex broaderIndex : hlist) {

                if(broaderIndex.getCreateTime()!= null && broaderIndex.getBroaderIndex()!= null){
                    //存入24个小时以内数据 && 10分钟一个维度
                    if (DateUtils.getDaysBetweenTwoHours(new Date(), broaderIndex.getCreateTime()) <= betweenHours) {
                        int value = broaderIndex.getCreateTime().getMinutes()/betweenMin ;
                        if(temp != value){
                            x.add(String.valueOf(broaderIndex.getCreateTime().getTime()));
                            y.add(broaderIndex.getBroaderIndex().setScale(2,BigDecimal.ROUND_DOWN).toString());
                            temp = value;
                        }
                    }
                }

            }
        }
        chartVo.setX(x);
        chartVo.setY(y);
        return  chartVo;
    }

    /**
     * 7天的大盘曲线 取值1小时
     * @return
     * @throws HbaseCloseExcetion
     * @throws IOException
     * @throws HbaseGetTableExcetion
     * @throws HbaseConnectionExcetion
     */
    public ChartVo getBroaderIndexOf7Day() throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {

        int betweenDay = 7;

        ChartVo chartVo = new ChartVo();

        List<String> x = new LinkedList<>();
        List<String> y = new LinkedList<>();

        List<BroaderIndex> hlist = new ArrayList<>();

        Long hstart = System.currentTimeMillis();
        for (int i = betweenDay; i > 0; i--) {
            String rowKey = DateUtils.getNextDayDateYMD(i * -1);
            String grailStr = getBroaderData(rowKey);
            if(StringUtils.isNotBlank(grailStr)){
                hlist.addAll(JSONObject.parseArray(grailStr, BroaderIndex.class)) ;
            }
        }
        LogTrace.info("大盘指数7天数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));

        if (hlist.size() > 0) {
            int temp = -1;
            for (BroaderIndex broaderIndex : hlist) {
                if(broaderIndex.getCreateTime()!= null && broaderIndex.getBroaderIndex()!= null){
                    //存入每个小时第一条数据
                    int huors = broaderIndex.getCreateTime().getHours();
                    if (huors != temp) {
                        x.add(String.valueOf(broaderIndex.getCreateTime().getTime()));
                        y.add(broaderIndex.getBroaderIndex().setScale(2,BigDecimal.ROUND_DOWN).toString());
                        temp = huors;
                    }
                }

            }
        }
        chartVo.setX(x);
        chartVo.setY(y);
        return  chartVo;
    }

    /**
     * 30天的大盘曲线 取值4小时
     * @return
     * @throws HbaseCloseExcetion
     * @throws IOException
     * @throws HbaseGetTableExcetion
     * @throws HbaseConnectionExcetion
     */
    public ChartVo getBroaderIndexOf30Day() throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {

        int betweenDay = 30;
        int betweenHours = 4;

        ChartVo chartVo = new ChartVo();

        List<String> x = new LinkedList<>();
        List<String> y = new LinkedList<>();

        List<BroaderIndex> hlist = new ArrayList<>();

        Long hstart = System.currentTimeMillis();
        for (int i = betweenDay; i > 0; i -- ) {
            String rowKey = DateUtils.getNextDayDateYMD(i * -1);
            String grailStr = getBroaderData(rowKey);
            if(StringUtils.isNotBlank(grailStr)){
               List<BroaderIndex> tempOneData = (JSONObject.parseArray(grailStr, BroaderIndex.class)) ;
                int temp = -1;
                for (BroaderIndex broaderIndex : tempOneData) {
                    if(broaderIndex.getCreateTime()!= null && broaderIndex.getBroaderIndex()!= null){
                        // 获取每4小时的一条大盘是数据
                        int tempValue = broaderIndex.getCreateTime().getHours() / betweenHours;
                        if(tempValue != temp){
                            hlist.add(broaderIndex);
                            temp = tempValue;
                        }
                    }
                }

            }
        }
        LogTrace.info("大盘指数30天数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));

        if (hlist.size() > 0) {
            for (BroaderIndex broaderIndex : hlist) {
                x.add(String.valueOf(broaderIndex.getCreateTime().getTime()));
                y.add(broaderIndex.getBroaderIndex().setScale(2,BigDecimal.ROUND_DOWN).toString());
            }
        }
        chartVo.setX(x);
        chartVo.setY(y);
        return  chartVo;
    }

    /**
     * 一年的大盘曲线 取值1天
     * @return
     * @throws HbaseCloseExcetion
     * @throws IOException
     * @throws HbaseGetTableExcetion
     * @throws HbaseConnectionExcetion
     */
    public ChartVo getBroaderIndexOfYear() throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {

        int betweenDay = 365;

        ChartVo chartVo = new ChartVo();

        List<String> x = new LinkedList<>();
        List<String> y = new LinkedList<>();

        List<BroaderIndex> hlist = new ArrayList<>();

        Long hstart = System.currentTimeMillis();
        for (int i = betweenDay; i > 0; i--) {
            String rowKey = DateUtils.getNextDayDateYMD(i * -1);
            String grailStr = getBroaderData(rowKey);
            if(StringUtils.isNotBlank(grailStr)){
                List<BroaderIndex> tempOneData = (JSONObject.parseArray(grailStr, BroaderIndex.class)) ;
                //获取每天的第一条
                hlist.add(tempOneData.get(0)) ;
            }
        }
        LogTrace.info("大盘指数一年(全部)数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));

        if (hlist.size() > 0) {
            for (BroaderIndex broaderIndex : hlist) {
                x.add(String.valueOf(broaderIndex.getCreateTime().getTime()));
                y.add(broaderIndex.getBroaderIndex().setScale(2,BigDecimal.ROUND_DOWN).toString());
            }
        }
        chartVo.setX(x);
        chartVo.setY(y);
        return  chartVo;
    }

    /**
     * 赚钱效应组装
     * @throws HbaseCloseExcetion
     * @throws IOException
     * @throws HbaseGetTableExcetion
     * @throws HbaseConnectionExcetion
     */
    public GraliIntensity MarkMoneyEffectToCacheCalculation() throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {
        GraliIntensity vo = new GraliIntensity();
        String grailStr = null;
        //计算24小时前rowkey  getLastHourDateStr
        //String rowkey = DateUtils.getCurrentDateString();
        //获取当前小时
        String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
        String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
        int hourStrInt = Integer.valueOf(hourStr);
        ChartVo charDate = new ChartVo();
        List<String> x = new LinkedList<>();
        List<ApiChartYObject> y = new LinkedList<>();
        int ci =0;//记录最后数据,记录rowkey是否改变，如果等于一代表第一次改变，需要重新获取hbase数据
        ApiChartYObject charY = null;
        Map<String,Object> hbaseData = new HashMap<>();//记录数据
        //获取两天hbase数据
        for(int day =0;day < 2;day++){
            String rowkey = DateUtils.getNextDayDateYMD(-day);//取rowkey
            Long hstart = System.currentTimeMillis();
            grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.DAILY_MONEY_EFFECT_INFO_TABLE_NAME
                    , HbaseTableUtils.DAILY_MONEY_EFFECT_INFO_TABLE_FAMILY
                    , HbaseTableUtils.DAILY_MONEY_EFFECT_INFO_TABLE_QUALIFIER
                    , rowkey);
            hbaseData.put(rowkey,grailStr);
            LogTrace.info("赚钱效应数据化hbase数据查询","耗时"+rowkey,String.valueOf(System.currentTimeMillis()-hstart));
            LogTrace.info("赚钱效应数据化hbase数据查询","是否存在数据"+rowkey,StringUtils.isBlank(grailStr)?"无数据":"有数据");
        }
        for(int i=0;i<24;i++){
            String nowRowKey = DateUtils.getLastHourDateStrOfDate(i);
            grailStr = (String) hbaseData.get(nowRowKey);
            if(StringUtils.isBlank(grailStr)){
                continue;
            }
            int nowHour = hourStrInt;
            if(hourStrInt==0){
                hourStrInt =23;
            }else{
                hourStrInt--;
            }
            if(StringUtils.isBlank(grailStr))  continue;
            Map<String,Object> moneyEffect = (Map<String, Object>) JSON.parse(grailStr);
            //获取当前时间数据
            Object o = moneyEffect.get(nowHour);
            if(o != null){
                List<MoneyEffect> listMoney = JSON.parseArray(JSON.toJSONString(o),MoneyEffect.class);
                for(int k =listMoney.size()-1;k>=0;k--){
                    MoneyEffect effect = listMoney.get(k);
                    if(effect.getCreateTime() == null || effect.getPerformance() == null) continue;
                    x.add(String.valueOf(effect.getCreateTime().getTime()));
                    charY = new ApiChartYObject();
                    charY.setComment(StringUtils.isNotBlank(effect.getComment())?effect.getComment():"");
                    charY.setScore(effect.getScore().toString());
                    charY.setValue(effect.getPerformance().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    y.add(charY);
                }
                //最新数据评分放入到最外层
                if(ci==0 && listMoney != null && listMoney.size() >0){
                    int mongyLength = listMoney.size();
                    vo.setScore(listMoney.get(mongyLength-1).getScore()!=null?listMoney.get(mongyLength-1).getScore().toString():"0");
                    vo.setResult(listMoney.get(mongyLength-1).getComment()!=null?listMoney.get(mongyLength-1).getComment():"");
                    vo.setCoinPerformance(listMoney.get(mongyLength-1).getPerformance()!=null?Double.valueOf(listMoney.get(mongyLength-1).getPerformance().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString()):0);
                    vo.setTime(listMoney.get(mongyLength-1).getCreateTime()!=null?String.valueOf(listMoney.get(mongyLength-1).getCreateTime().getTime()):"");
                    ci++;
                }
            }else{
                LogTrace.info("某个小时小时是否存在数据",String.valueOf(nowHour),"无数据");
            }
        }
        vo.setInterpretationId(2);
        vo.setInterpretation("赚钱效应");
        vo.setExplanation("昨日涨幅超过6%的货币今日表现是昨日投资的延续，当持续的收益表现良好时，一定程度上表明资金持续流入，市场走势趋强，反之则弱。");
        Collections.reverse(x);
        Collections.reverse(y);
        charDate.setX(x);
        charDate.setY(y);
        vo.setChart(charDate);

        return vo;
    }

    /**
     * 量能变化5分钟组装数据到redis中
     * @throws Exception
     */
    public ApiMarketInterpretationChange MarketInterpretationChangeToCacheCalculation() throws Exception{
        //计算24小时前rowkey  getLastHourDateStr
        //String rowkey = DateUtils.getCurrentDateString();

        ApiMarketInterpretationChange vo = new ApiMarketInterpretationChange();
        //获取当前小时
        String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
        String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
        int hourStrInt = Integer.valueOf(hourStr);
        MoreChartVo charDate = new MoreChartVo();
        List<String> x = new LinkedList<>();
        List<ApiChartYObject> y = new LinkedList<>();
        List<ApiChartYObject> y1 = new LinkedList<>();
        String grailStr = null;
        Map<String,Object> hbaseData = new HashMap<>();//记录数据
        //获取两天hbase数据
        for(int day =0;day > -2;day--){
            String rowkey = DateUtils.getNextDayDateYMD(day);//取rowkey
            Long hstart = System.currentTimeMillis();
            grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.DAILY_QUANTUM_ENERGY_INFO_TABLE_NAME
                    , HbaseTableUtils.DAILY_QUANTUM_ENERGY_INFO_TABLE_FAMILY
                    , HbaseTableUtils.DAILY_QUANTUM_ENERGY_INFO_QUALIFIER
                    , rowkey);
            hbaseData.put(rowkey,grailStr);
            LogTrace.info("大盘量能变化hbase数据查询","是否存在数据"+rowkey,StringUtils.isBlank(grailStr)?"无数据":"有数据");
            LogTrace.info("大盘量能变化hbase数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));
        }
        int ci =0;//记录最后数据
        ApiChartYObject charY = null;
        for(int i=0;i<24;i++){
            String nowRowKey = DateUtils.getLastHourDateStrOfDate(i);
            grailStr = (String) hbaseData.get(nowRowKey);
            if(StringUtils.isBlank(grailStr)){
                continue;
            }
            int nowHour = hourStrInt;
            if(hourStrInt==0){
                hourStrInt =23;
            }else{
                hourStrInt--;
            }
            if(StringUtils.isBlank(grailStr))  continue;
            Map<String,Object> moneyEffect = (Map<String, Object>) JSON.parse(grailStr);
            Object o = moneyEffect.get(nowHour);//获取当前时间数据
            if(o != null){
                List<QuantumEnergy> listMoney = JSON.parseArray(JSON.toJSONString(o),QuantumEnergy.class);
                for(int k =listMoney.size()-1;k>=0;k--){
                    QuantumEnergy energy = listMoney.get(k);
                    if(energy == null || energy.getCreateTime() == null || energy.getAvgPrice() == null || energy.getAvgTurnover24h() == null){
                        continue; //判断内容不完整直接过滤
                    }
                    x.add(String.valueOf(energy.getCreateTime().getTime()));
                    charY = new ApiChartYObject();
                    charY.setScore(energy.getScore().toString());
                    charY.setValue(energy.getAvgPrice()!=null?energy.getAvgPrice().setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                    charY.setComment(StringUtils.isNotBlank(energy.getComment())?energy.getComment():"");
                    y.add(charY);
                    //y.add(energy.getAvgPrice()!=null?energy.getAvgPrice().setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                    charY = new ApiChartYObject();
                    charY.setScore(energy.getScore().toString());
                    charY.setComment(StringUtils.isNotBlank(energy.getComment())?energy.getComment():"");
                    charY.setValue(energy.getAvgTurnover24h()!=null?energy.getAvgTurnover24h().divide(BigDecimal.valueOf(100000000)).setScale(2,BigDecimal.ROUND_DOWN).toString():"");
                    y1.add(charY);
                }
                if(ci==0){//最新数据评分放入到最外层
                    int mongyLength = listMoney.size();
                    vo.setScore(listMoney.get(mongyLength-1).getScore()!=null?listMoney.get(mongyLength-1).getScore().toString():"");
                    vo.setResult(listMoney.get(mongyLength-1).getComment()!=null?listMoney.get(mongyLength-1).getComment():"");
                    vo.setAveragePrice(listMoney.get(mongyLength-1).getAvgPrice().setScale(2,BigDecimal.ROUND_DOWN).toString());
                    vo.setAverageVolume(listMoney.get(mongyLength-1).getAvgTurnover24h().divide(BigDecimal.valueOf(100000000)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    vo.setTime(listMoney.get(mongyLength-1).getCreateTime()!=null?String.valueOf(listMoney.get(mongyLength-1).getCreateTime().getTime()):"");
                }
                ci++;
            }else{
                LogTrace.info("某个小时小时是否存在数据",String.valueOf(nowHour),"无数据");
            }
        }
        //插入解释
        vo.setInterpretationId(2);
        vo.setInterpretation("量能变化");
        vo.setExplanation("用权重货币的价格以及每个货币被赋予的固定权重加权平均得到权重货币的价格指数，比较价格指数与权重货币交易额之间的关系，可以分析出近期大盘的走势。");
        Collections.reverse(x);
        Collections.reverse(y);
        Collections.reverse(y1);
        charDate.setX(x);
        charDate.setY(y);
        charDate.setY2(y1);
        vo.setChart(charDate);
        return vo;
    }

    /**
     * 权重表现5分钟组装数据到redis中
     * @throws Exception
     */
    public ApiMarketWeightsPerformance MarketWeightsPerformanceToCacheCalculation() throws Exception{
        ApiMarketWeightsPerformance vo = new ApiMarketWeightsPerformance();
        String grailStr = null;
        //获取当前小时
        String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
        String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
        int hourStrInt = Integer.valueOf(hourStr);
        ChartVo charDate = new ChartVo();
        List<String> x = new LinkedList<>();
        List<ApiChartYObject> y = new LinkedList<>();
        Map<String,Object> hbaseData = new HashMap<>();//记录数据
        //获取两天hbase数据
        for(int day =0;day > -2;day--){
            String rowkey = DateUtils.getNextDayDateYMD(day);//取rowkey
            Long hstart = System.currentTimeMillis();
            grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.DAILY_WEIGHT_PERFORMANCE_INFO_TABLE_NAME
                    , HbaseTableUtils.DAILY_WEIGHT_PERFORMANCE_INFO_TABLE_FAMILY
                    , HbaseTableUtils.DAILY_WEIGHT_PERFORMANCE_INFO_TABLE_QUALIFIER
                    , rowkey);
            hbaseData.put(rowkey,grailStr);
            LogTrace.info("权重表现hbase数据查询","是否存在数据"+rowkey,StringUtils.isBlank(grailStr)?"无数据":"有数据");
            LogTrace.info("权重表现hbase数据查询","耗时",String.valueOf(System.currentTimeMillis()-hstart));
        }
        int ci =0,rowKeySame=0;//记录最后数据,记录rowkey是否改变，如果等于一代表第一次改变，需要重新获取hbase数据
        ApiChartYObject charY = null;
        //取24小时内的数据
        for(int i=0;i<24;i++){
            String nowRowKey = DateUtils.getLastHourDateStrOfDate(i);
            grailStr = (String) hbaseData.get(nowRowKey);
            if(StringUtils.isBlank(grailStr)){
                continue;
            }
            int nowHour = hourStrInt;
            if(hourStrInt==0){
                hourStrInt =23;
            }else{
                hourStrInt--;
            }
            if(StringUtils.isBlank(grailStr))  continue;
            Map<String,Object> weightsPerformanceMap = (Map<String, Object>) JSON.parse(grailStr);
            Object o = weightsPerformanceMap.get(nowHour);//获取当前时间数据
            if(o != null){
                List<WeightsPerformance> listMoney = JSON.parseArray(JSON.toJSONString(o),WeightsPerformance.class);
                for(int k =listMoney.size()-1;k>=0;k--){
                    WeightsPerformance wieghtPer = listMoney.get(k);
                    if(wieghtPer == null || wieghtPer.getCreateTime() == null || wieghtPer.getPerformance() == null){
                        continue; //判断内容不完整直接过滤
                    }
                    x.add(String.valueOf(wieghtPer.getCreateTime().getTime()));
                    charY = new ApiChartYObject();
                    charY.setScore(wieghtPer.getScore().toString());
                    charY.setComment(StringUtils.isNotBlank(wieghtPer.getComment())?wieghtPer.getComment():"");
                    charY.setValue(wieghtPer.getPerformance().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    y.add(charY);
                }
                if(ci == 0){//最新数据评分放入到最外层
                    int mongyLength = listMoney.size();
                    vo.setScore(listMoney.get(mongyLength-1).getScore().toString());
                    vo.setResult(listMoney.get(mongyLength-1).getComment());
                    vo.setWeightsPerformance(listMoney.get(mongyLength-1).getPerformance().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString());
                    vo.setTime(listMoney.get(mongyLength-1).getCreateTime()!=null?String.valueOf(listMoney.get(mongyLength-1).getCreateTime().getTime()):"");
                    ci++;
                }
            }else{
                LogTrace.info("某个小时小时是否存在数据",String.valueOf(nowHour),"无数据");
            }
        }
        vo.setInterpretationId(3);
        vo.setInterpretation("权重表现");
        vo.setExplanation("权重货币是市值较大，具有代表性的20种货币，权重货币的价格涨幅越大，说明主力进场明显，反之则说明主力出逃明显。");
        Collections.reverse(x);
        Collections.reverse(y);
        charDate.setX(x);
        charDate.setY(y);
        vo.setChart(charDate);
        return vo;
    }
}
